package com.zhenhao.xsq.utils;

import android.annotation.SuppressLint;
import android.text.TextUtils;


import com.blankj.utilcode.util.GsonUtils;
import com.blankj.utilcode.util.SPUtils;
import com.orhanobut.logger.Logger;
import com.zhenhao.xsq.contain.Contains;
import com.zhenhao.xsq.entity.BleEntity;
import com.zhenhao.xsq.entity.login.UserEntity;


public class SpSaveUtils {

    /**
     * 保存是否开启指纹
     *
     * @param fingerState
     */
    public static void putFingerState(boolean fingerState) {
        SPUtils.getInstance().put(Contains.SP_FINGER_STATE, fingerState);
    }

    public static boolean getFingerState() {
        return SPUtils.getInstance().getBoolean(Contains.SP_FINGER_STATE, false);
    }

    /**
     * 保存是否开启图案
     *
     * @param fingerState
     */
    public static void putPatternState(boolean fingerState) {
        SPUtils.getInstance().put(Contains.SP_PATTERN_STATE, fingerState);
    }

    public static boolean getPatternState() {
        return SPUtils.getInstance().getBoolean(Contains.SP_PATTERN_STATE, false);
    }

    /**
     * 保存是否开启推送
     *
     * @param pushService
     */
    public static void putPushService(boolean pushService) {
        SPUtils.getInstance().put(Contains.SP_PUSH_SERVICE, pushService);
    }

    public static boolean getPushService() {
        return SPUtils.getInstance().getBoolean(Contains.SP_PUSH_SERVICE, true);
    }

    /**
     * toobar颜色
     *
     * @param ischange false 白色  true 蓝色
     */
    public static void putToolbarColor(boolean ischange) {
        SPUtils.getInstance().put(Contains.SP_TOOLBAR_COLOR, ischange);
    }

    public static boolean getToolbarColor() {
        return SPUtils.getInstance().getBoolean(Contains.SP_TOOLBAR_COLOR, false);
    }

    /**
     * toobar颜色
     *
     * @param colorState 0 白色(默认) 1 蓝色 2橘色 3黑色
     */
    public static void putToolbarColor(int colorState) {
        SPUtils.getInstance().put(Contains.SP_TOOLBAR_COLOR_NUM, colorState);
    }

    public static int getToolbarColorNum() {
        return SPUtils.getInstance().getInt(Contains.SP_TOOLBAR_COLOR_NUM, 0);
    }

    /**
     * 保存时时token
     *
     * @param accessToken
     */
    public static void putAccessToken(String accessToken) {
        SPUtils.getInstance().put(Contains.SP_ACCESS_TOKEN, accessToken);
    }

    public static String getAccessToken() {
        return SPUtils.getInstance().getString(Contains.SP_ACCESS_TOKEN);
    }

    /**
     * 保存刷新token
     *
     * @param refreshToken
     */
    public static void putRefreshToken(String refreshToken) {
        SPUtils.getInstance().put(Contains.SP_REFRESH_TOKEN, refreshToken);
    }

    public static String getRefreshToken() {
        return SPUtils.getInstance().getString(Contains.SP_REFRESH_TOKEN);
    }

    /**
     * 保存项目编号
     *
     * @param number
     */
    public static void putXmNumber(String number) {
        SPUtils.getInstance().put(Contains.SP_XM_NUMBER, number);
    }

    public static String getXmNumber() {
        return SPUtils.getInstance().getString(Contains.SP_XM_NUMBER);
    }

    /**
     * 保存业主id
     *
     * @param userid
     */
    public static void putUserId(String userid) {
        SPUtils.getInstance().put(Contains.SP_USER_ID, userid);
    }

    public static String getUserId() {
        return SPUtils.getInstance().getString(Contains.SP_USER_ID);
    }

    /**
     * 是否记住当前房屋
     *
     * @param ischange false 不  true 是
     */
    public static void putCheckFw(boolean ischange) {
        SPUtils.getInstance().put(Contains.SP_FW_ISCHECK, ischange);
    }

    public static boolean getCheckFw() {
        return SPUtils.getInstance().getBoolean(Contains.SP_FW_ISCHECK, true);
    }

    /**
     * 保存房屋fwid
     *
     * @param fwid
     */
    public static void putFwId(String fwid) {
        SPUtils.getInstance().put(Contains.SP_FW_ID, fwid);
    }

    public static String getFwId() {
        return SPUtils.getInstance().getString(Contains.SP_FW_ID);
    }

    /**
     * 保存房屋编号
     *
     * @param fwbh
     */
    public static void putFwBh(String fwbh) {
        SPUtils.getInstance().put(Contains.SP_FW_BH, fwbh);
    }

    public static String getFwBh() {
        return SPUtils.getInstance().getString(Contains.SP_FW_BH);
    }

    /**
     * 保存房屋信息
     *
     * @param treeJson
     */
    public static void putFwInfoJson(String treeJson) {
        SPUtils.getInstance().put(Contains.SP_FW_INFO, treeJson);
    }

    public static UserEntity.DataBean.HouseVosBean getFwInfoJson() {
        return GsonUtils.fromJson(SPUtils.getInstance().getString(Contains.SP_FW_INFO),
                UserEntity.DataBean.HouseVosBean.class);
    }

    /**
     * 保存人脸信息
     *
     * @param headUrl
     */
    public static void putYzInfoHead(String headUrl) {
        SPUtils.getInstance().put(Contains.SP_HEAD_URL, headUrl);
    }

    public static String getYzInfoHead() {
        return SPUtils.getInstance().getString(Contains.SP_HEAD_URL);
    }

    /**
     * 保存业主信息
     *
     * @param treeJson
     */
    public static void putYzInfoJson(String treeJson) {
        SPUtils.getInstance().put(Contains.SP_YZ_INFO, treeJson);
    }

    public static UserEntity.DataBean.YezhuVoBean getYzInfoJson() {
        return GsonUtils.fromJson(SPUtils.getInstance().getString(Contains.SP_YZ_INFO),
                UserEntity.DataBean.YezhuVoBean.class);
    }

    /**
     * 保存用户信息
     *
     * @param treeJson
     */
    public static void putUserInfoJson(String treeJson) {
        SPUtils.getInstance().put(Contains.SP_USER_INFO, treeJson);
    }

    public static UserEntity getUserInfoJson() {
        return GsonUtils.fromJson(SPUtils.getInstance().getString(Contains.SP_USER_INFO), UserEntity.class);
    }

    /**
     * 保存蓝牙门禁信息
     *
     * @param treeJson
     */
    public static void putBleInfoJson(String treeJson) {
        SPUtils.getInstance().put(Contains.SP_BLE_LIST, treeJson);
    }

    public static BleEntity getBleInfoJson() {
        return GsonUtils.fromJson(SPUtils.getInstance().getString(Contains.SP_BLE_LIST), BleEntity.class);
    }

    /**
     * 清除缓存
     */
    public static void clearSp() {
        Logger.i("清除缓存数据");
        SPUtils.getInstance().clear();
    }

}
